Rewriting table functions as SQL strings

ABSTRACT

The TABLE function mechanism available in a RDBMS is used to integrate RDF models into SQL queries. The table function invocation takes parameters including an RDF pattern, an RDF model, and an RDF rule base and returns result rows to the SQL query that contain RDF triples resulting from the application of the pattern to the triples of the model and the triples inferred by applying the rule base to the model. The RDBMS includes relational representations of the triples and the rules. Optimizations include indexes and materialized views of the representations of the triples, precomputed inferred triples, and a method associated with the TABLE function that rewrites the part of the SQL query that contains the TABLE function invocation as an equivalent SQL string. The latter technique is generally applicable to TABLE functions.

CROSS REFERENCES TO RELATED PATENT APPLICATIONS

The subject matter of this patent application is closely related to thesubject matter of patent application U.S. Ser. No. __/______,Integrating RDF data into a relational database system, which has thesame inventors and assignee as the present patent application and isbeing filed on even date with this application. U.S. Ser. No. __/______is further incorporated by reference into this patent application forall purposes.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The invention concerns the representation of semantic knowledge by theResource Description Framework, or RDF, and more specifically concernsthe integration of data represented by RDF into a relational databasesystem.

2. Description of Related Art: FIGS. 1-3

RDF is a language that was originally developed for representinginformation (metadata) about resources in the World Wide Web. It may,however, be used for representing information about absolutely anything.When information has been specified using the generic RDF format, it maybe automatically consumed by a diverse set of applications.

FIGS. 1-3 provide an overview of RDF. Facts in RDF are represented byRDF triples. Each RDF triple represents a fact and is made up of threeparts, a subject, a predicate, (sometimes termed a property), and anobject. For example, the fact represented by the English sentence “Johnis 24 years old” is represented in RDF by the subject, predicate, objecttriple <‘John’, ‘age’, ‘24’>, with ‘John’ being the subject, ‘age’ beingthe predicate, and ‘24’ being the object. In current RDF, the values ofsubjects and predicates must ultimately resolve to universal resourceidentifiers (URIs). The values of objects may be literal values such asnumbers or character strings. The interpretations given to the membersof the triple are determined by the application that is consuming it.RDF triples may be represented as a graph as shown at 109 in FIG. 1. Thesubject is represented by a node 103, the object by another node 107,and the predicate by arrow 104 connecting the subject node to the objectnode. A subject may of course be related to more than one object, asshown with regard to “Person” 103. Each entity in an RDF triple isrepresented by a World Wide Web Uniform Resource Identifier (URI) or aliteral value. For example, the subject “John” is identified by the URIfor his contact information. In RDF triple 117, the value of John's ageis the literal value 24. In the following general discussion of RDF, theURIs will be replaced by the names of the entities they represent. For acomplete description of RDF, see Frank Manola and Eric Miller, RDFPrimer, published by W3C and available in September, 2004 atwww.w3.org/TR/rdf-primer/. The RDF Primer is hereby incorporated byreference into the present patent application.

An RDF representation of a set of facts is termed in the following anRDF model. A simple RDF model Reviewers is shown at 101 in FIG. 1. Themodel has two parts: RDF data 113 and RDF schema 111. RDF schema 111 ismade up of RDF triples that provide the definitions needed to interpretthe triples of RDF data 113. Schema triples define classes of entitiesand predicates which relate classes of entities. A property definitionfor the predicate age is shown at 112. As shown there, a predicatedefinition consists of two RDF triples for which the predicate is thesubject. One of the triples, which has the built-in domain predicate,indicates what kind of entities must be subjects for the predicate.Here, it is entities belonging to the class person. The other tripleindicates what kinds of entities must be objects of the predicate; here,it is values of an integer type called xsd:int. Schema 111 uses theSubclassOf predicate 110 to define a number of subclasses of entitiesbelonging to the class person. Also defined are conference anduniversity classes of entities, together with predicates that relatethese entities to each other. Thus, an entity of class person may be achairperson of a conference and an entity of class reviewer may be areviewer for a conference. Also belonging to Schema 111 but not shownthere is the built-in RDF predicate rdf:type. This predicate defines thesubject of a triple that includes the rdf:type predicate as an instanceof the class indicated by the object. As will be explained in moredetail, RDF rules determine logical relationships between classes. Forexample, a built-in RDF rule states that the SubclassOf relationship istransitive: if A is a subclass of B and B a subclass of C, then A is asubclass of C. Thus, the class faculty is a subclass of person.

The data triples to which schema 111 applies are shown at 113; they havethe general pattern <individual entity>, <predicate>, <objectcharacterizing the individual entity>. Thus, triple 115 indicates thatICDE 2005 is an entity characterized as belonging to the classCONFERENCE and triple 117 indicates that JOHN is characterized by havingthe age 24. Thus, RDF data 113 contains the following triples aboutJohn:

-   -   John has an Age of 24;    -   John belongs to the subclass Ph. D. Student;    -   John is a ReviewerOf ICDE 2005.

None of these triples states that John is a Person; however, the factthat he is a Person and a Reviewer is inferred from the fact that he isstated to be a Ph. D. Student, which is defined in schema 111 as asubclass of both Person and Reviewer. Because the Subclassof predicateis transitive, the fact that John is a Ph.D Student means that he is apotential subject of the Age and ReviewerOf properties.

For purposes of the present discussion RDF models are best representedas lists of RDF triples instead of graphs. FIG. 2 shows a table oftriples 201 which lists triples making up schema 111 and a table oftriples 203 which lists triples making up RDF data 113. At the bottom ofFIG. 2 is an RDF Pattern 205. An RDF pattern is a construct which isused to query RDF triples. There are many different ways of expressingRDF patterns; what follows is a typical example. When RDF pattern 205 isapplied to RDF model 101, it will return a subgraph of RDF model 101which includes all of the reviewers of conference papers who are Ph.Dstudents. The pattern is made up of one or more patterns 207 for RDFtriples followed by an optional filter which further restricts the RDFtriples identified by the pattern. The identifiers beginning with? arevariables that represent values in the triples belonging to the subgraphspecified by the RDF pattern. Thus, the first pattern 207(1) specifiesevery Reviewer for every Conference indicated in the RDF data 203; thesecond pattern 207(2) specifies every Reviewer who belongs to thesubclass Ph.D. Student, and the third pattern 207(3) specifies everyPerson for which an Age is specified. The result of the application ofthese three patterns to RDF data 203 is the intersection of the sets ofpersons specified by each of the patterns, that is, the intersection ofthe set of reviewers and the set of Ph.D. Students of any age. Theintersection is John, Tom, Gary, and Bob, who are indicated by thetriples in data 203 as being both Ph.D students and reviewers.

The manner in which entities in an RDF model relate to each other can bemodified by applying RDF rules. An example RDF rule is shown at 301 inFIG. 3. Rule 301 is contained in a rulebase which, as shown at 303, hasthe name rb. The rule has a name, chairpersonRule, which is shown at305. As will be explained in detail later, the rule specifies how theclass of Persons who are conference chairpersons relates to the class ofReviewers for the conference. Rule body 310 has a left-hand side 307specifying the rule's antecedent and a right-hand side 311 specifyingthe rule's consequent. The rule states that if an entity satisfies theconditions established for the left-hand side 307 (the antecedent), italso satisfies the conditions established for the right-hand side 311(the consequent). The antecedent and the consequent are specified by RDFpatterns. The RDF pattern for left-hand side 307 specifies any Person(?r) in the model who is a chairperson of any Conference (?c) in themodel; the RDF pattern for right-hand side 311 specifies that any suchperson is also a reviewer for that conference.

RDF pattern 312 shows the effect of rule 301. The pattern's triplespecifies RDF triples which have the ReviewerOf predicate. Without rule301, the pattern returns the subjects of those triples for ?r, or John,Tom, Gary, and Bob. The problem with this is that Mary is also areviewer by virtue of rule 301; consequently, when the rule is takeninto account, the triples include not only those with the ReviewerOfpredicate, but those that have the Chairpersonof predicate, and thatadds Mary to the list of subjects for ?r. An RDF model 101 and the rulesand other information required to interpret the model are termedtogether in the following an RDF dataset Components of an RDF data setare shown at 313 in FIG. 3. The components include RDF model 101, withits schema 111 and RDF data 113, one or more optional rulebasescontaining rules relevant to the model, and a list of optional aliases323, which relate names used in the model to longer designations.

The rulebases include an RDFS rulebase 319 which is a set of rules whichapply to all RDF models. An example of the rules in this rulebase is therule that states that an entity which belongs to a subclasss of a classalso belongs to the class, for example, that as a member of the classPh.D. Student, John is also a member of the class Person. In addition,rules may be defined for a particular RDF model. Rule 301 is an exampleof such a rule. These rules are contained in one or more other rulebases 321. Aliases 323 relates short names used in a model to the URIsthat completely identify the short name. For example, John, Mary, Tom,Gary, and Bob are all subjects and must therefore be identified by URIs.Aliases 323 will include a table that relates each name to itscorresponding URI.

Systems for Querying RDF Models

A number of query languages have been developed for querying RDF models.Among them are:

-   -   RDQL, see RDQL—A Query Language for RDF, W3C Member Submission 9        Jan. 2004, http://www.w3.org/Submission/2004/SUBM-RDQL-20040109;    -   RDFQL, see RDFQL Database Command Reference,        http://www.intellidimension.com/default.rsp?topic=/pages/rdfgateway/reference/db/default.rsp;    -   RQL, see G. Karvounarakis, S. Alexaki, V. Christophides, D.        Plexousakis, M. Scholl. RQL: A Declarative Query Language for        RDF. WWW2002, May 7-11, 2002, Honolulu, Hi., USA.    -   SPARQL, see SPARQL Query Language for RDF, W3C Working Draft, 12        Oct. 2004,        http://www.w3.org/TR/2004/WD-rdf-sparql-query-20041012/.    -   SquishQL, see RDF Primer. W3C Recommendation, 10 Feb. 2004,        http://www.w3.org/TR/rdf-primer.

The query languages described in the above references are declarativequery languages with quite a few similarities to SQL, which is the querylanguage used in standard relational database management systems.Indeed, systems using these query languages are typically implemented ontop of relational database systems. However, because these systems arenot standard relational database systems, they cannot take advantage ofthe decades of engineering that have been invested in the standardrelational database systems. Examples of the fruits of this engineeringthat are available in standard relational database systems are automaticoptimization, facilities for the creation and automatic maintenance ofmaterialized views and of indexes, and the automatic use of availablematerialized views and indexes by the optimizer. What is needed if RDFtriples are to reach their full potential are a technique for using RDFpatterns to query sets of RDF triples that may be employed in a standardrelational data base management system and techniques for using thefacilities of the relational database management system to reduce thecost in processing time of queries on sets of RDF triples.

The techniques used to integrate RDF data into a relational databasesystem involve the use of a TABLE function. Consequently, a large partof the cost in processing time of queries on sets of RDF triples is thetime required to set up the execution of the TABLE function, execute theTABLE function, and then transfer data from the TABLE function to theSQL query that contains the TABLE function. It is thus an object of thepresent invention to reduce the cost of execution of table functions.

SUMMARY OF THE INVENTION

The foregoing object of the invention is attained by associating arewrite method with the table function. The result rows returned by thetable function are represented in an SQL statement by a container forthe table function. The rewrite method returns an SQL string that whenexecuted returns a set of result rows that are equivalent to the resultrows returned when the table function is executed. The relationaldatabase management system executes the rewrite method to obtain the SQLstring prior to executing the SQL query that contains the TABLE functionand replaces the container for the table function by the returned SQLstring. Since the returned SQL string is simply part of the SQL query,it has none of the overhead of the required to set up the table functionfor execution, execute it, and transfer the data from the TABLE functionto the SQL query. A further advantage is that the relational databasemanagement system's optimizer can operate on the rewritten SQL query.

In other aspects of the invention, the table function has a parameterthat the rewrite method uses in producing the returned SQL string. Therewrite method determines from the parameter whether it is possible toproduce the SQL string and provides and indication to the relationaldatabase management system when that is not possible. The relationaldatabase management system responds to the indication by not rewritingthe SQL statement.

There may also be a runtime execution method associated with the TABLEfunction in addition to the rewrite method and the rewrite method may beoptional. When there is no rewrite method, the relational databasemanagement system executes the runtime execution method. The methods maybe provided by the relational database management system or by a user ofthe relational database management system. The container for the TABLEfunction may be a TABLE clause or a parameterized view that is definedusing the table function. Other objects and advantages will be apparentto those skilled in the arts to which the invention pertains uponperusal of the following Detailed Description and drawing, wherein:

BRIEF DESCRIPTION OF THE DRAWING

FIG. 1 shows RDF triples represented as graphs;

FIG. 2 shows tables of RDF triples and an RDF pattern;

FIG. 3 shows an RDF rule and RDF information;

FIG. 4 provides an overview of a relational database management systemin which the invention is implemented;

FIG. 5 shows an SQL query that contains an RDF_MATCH table function;

FIG. 6 shows RDF triple tables 445 in a preferred embodiment;

FIG. 7 is an illustration of an inferred triple index and the API formanipulating such indexes;

FIG. 8 is a flowchart of the operation of the RDF_MATCH table function;

FIG. 9 is an illustration of self joins;

FIG. 10 is an illustration of RDF_MATCH optimization tables 447;

FIG. 11 is an illustration of a subject-property matrix joinmaterialized view;

FIG. 12 is an illustration of a predicate, subject, object index;

FIG. 13 shows RDF patterns used to determine the efficiency of variouskinds of indexes;

FIG. 14 shows how rewriting the contained query can improve efficiency;

FIG. 15 is an example of rewriting;

FIG. 16 is a flowchart of optimization by rewriting;

FIG. 17 shows RDF rule tables 449 in a preferred environment;

FIG. 18 shows the API for manipulating rulebases in a preferredenvironment;

FIG. 19 shows the API for manipulating materialized views in a preferredenvironment; and

FIG. 20 shows further examples of the use of ODCITableRewrite.

Reference numbers in the drawing have three or more digits: the tworight-hand digits are reference numbers in the drawing indicated by theremaining digits. Thus, an item with the reference number 203 firstappears as item 203 in FIG. 2.

DETAILED DESCRIPTION

The following Detailed description will first present an overview of theinvention as embodied in a standard relational database managementsystem (RDBMS) and will then present details of a preferred embodiment.

Overview of the Invention

Overview of a RDBMS in Which the Invention is Implemented: FIG. 4

FIG. 4 is a functional block diagram of a relational database managementsystem 401 in which the invention is implemented. RDBMS's arecharacterized by the fact that the information they contain is organizedinto tables having rows and named columns. A row of data establishes arelationship between the items of data in the row and the SQL querylanguage uses the relationships thus established to locate informationin the tables. RDBMS system 401 may be any relational database systemwhich employs a variant of the SQL language that includes tablefunctions. As will be explained in more detail in the following, a tablefunction is a function which permits the RDBMS system to treat acollection of data that is obtained by the function as a table.

The main components of RDBMS system 401 are a processor 421, memory 403,which contains data and programs accessible to the processor, andpersistent storage 423, which contains the information organized bysystem 401. Processor 421 further can provide information to and receiveinformation from display and input devices 422, can provide informationto and receive information from networks 424, and can provideinformation to and receive information from file system 426. RDBMSsystem 401 is created by processor 421 as it executes programs in memory403 using data contained in memory. The programs typically include anoperating system 407, which manages the resources used by RDBMS 401,relational database program 409, which interprets the SQL language, andapplication programs 411, which provide queries to RDB program 409. Dataused by these programs includes operating system data 419, used by theoperating system RDBMS data 417, used by RDB program 409, andapplication program data 415, used by application programs 411.

The information which RDB program 409 maintains in persistent storage423 is stored as objects that RDBMS system 401 is able to manipulate.Among the objects are fields, rows, and columns in the tables, thetables themselves, indexes to the tables, and functions written in theSQL language. The objects fall into two broad classes: user-definedobjects 441, which are defined by users of the RDBMS, and system-definedobjects 425, which are defined by the system. RDBMS 401 maintainsdefinitions of all of the objects in the database system in datadictionary 427, which is part of DB system objects 425. For the presentdiscussion, the most important definitions in data dictionary 427 aretable definitions 429, which include definitions 431 of RDF tables 443,table function definitions 433, which define table functions includingRDF_MATCH table function 435, which permits use of RDF patterns to queryRDF models in RDBMS 401, and SQL function definitions 437, whichincludes RDF_GENMODEL function 439, which takes RDF triples and makesthem into RDF tables 443.

The tables of interest in user objects 441 are RDF tables 443, which aretables in RDBMS 401 that are made from the information contained in RDFinformation 313. These tables fall into three groups: RDF triple tables445, which represent the triples making up an RDF model 101, RDF ruletables 449, which contain the rule bases belonging to RDF information313, and RDF optimization objects 447, which are tables and otherobjects which are used to speed up queries on the RDF models representedby RDF triple tables 445 and the RDF rules in rules tables 449. All ofthese tables and objects will be explained in more detail below.

Overview of the Operation of the Invention: FIG. 5

The invention integrates RDF into SQL by means of a set of tables 445and 449 in user objects 441 that represent RDF data sets and a tablefunction RDF_MATCH that takes a specification of an RDF data set and anRDF pattern as parameters and returns a set of result rows of triplesfrom the RDF data set that match the RDF pattern. The solution of theRDF pattern may include inferencing based on RDFS and user-definedrules. The signature of RDF_MATCH is as follows:  RDF_MATCH (   PatternVARCHAR,   Models RDFModels,   RuleBases RDFRules,   Aliases RDFAliases, ) RETURNS AnyDataSet;

The first parameter is one or more character strings that indicate theRDF pattern to be used for the query. Typically, the character stringwill consist of one or more <Subject, Property, Object> triple patterns.The remaining parameters specify the RDF data set to be queried. Modelsspecifies the data set's RDF models, RuleBases specifies rule bases thatcontain the RDF rules that apply to The parameters of RDF_MATCH tablefunction 505 include the RDF pattern 507 which will be used to selectinformation from RDF model 101. In conjunction with the relationshipspecified at 504, the pattern assigns the person selected for each rowof t to the t.r column, the conference selected for each row of t to thet.c column and the person's age to the t.a column. As required by RDFpattern 507, the persons who will have rows in table t will be personswho are students and reviewers for any of the conferences indicated inRDF model 101. The remaining parameters are the following:

-   -   RDFMODELS 509 specifies the RDF model the query is being applied        to.    -   NULL 511 that no rule base is to be included;    -   NULL 513 indicates that no aliases are involved.

When SELECT statement 503 executes on RDF data triples 203, RDF_MATCH505 returns rows 516 which contain the information from the ?r, ?c, and?a fields belonging to the RDF triples that match RDF pattern 507. Inthis case, there is a row for each student reviewer-conferencecombination and each of the rows contains the student's age. In additionto the values for the RDF pattern's variables, the result rows indicatethe types of the object variables. That is necessary because objects mayhave either URI values or literal values. Thus, ?c specifiesconferences, which are specified by URI, so the result rows include thecolumn c$type, which indicates that the type of values of c is URI. Inthe case of a, the values are integer literal values, and a$typeindicates that fact.

SELECT statement 503 then selects fields belonging to the columns r, c,and a of rows 515 to produce result rows 514. The WHERE clause of SELECTstatement 503, finally, limits the result rows produced by the executionof the SELECT statement to ones in which the age of the people selectedby pattern 507 is less than 25. In this case, the WHERE clause has noeffect, since all of the student reviewers are under 25. It should benoted here that because the RDF schema also consists of RDF triples,RDF_MATCH can also be used to query an RDF schema, for example, toobtain the domains and ranges for a property.

An advantage of using the RDF_MATCH table function in a SELECT statementto query RDF data is that any SQL construct that can be used with aSELECT statement can be used to further process the result rows 516returned by RDF_match. These constructs include iterating over theresult rows, aggregating values contained in the result rows,constraining the result rows using WHERE clause predicates, sorting theresult rows using ORDER BY clauses, and limiting the result rows byusing the ROWNUM clause. Also, the SQL set operations can be used tocombine result sets of two or more invocations of RDF_MATCH. Support forOPTIONAL matching (as described in the SPARQL reference) can be providedusing the OUTER JOIN operation in SQL.

An example of how the SQL COUNT and AVG constructs might be used in aSELECT statement that contains table function 505 is shown at 515. Query515 specified by SELECT statement 517 uses the same FROM TABLE clause507 as query 501 and consequently the same RDF model and the same RDFpattern, but the query returns a set of result rows that specify foreach conference, the number of student reviewers for the conference andthe average age for the conference. The returned result rows are shownat 523. Result rows 523 are made from information in the rows returnedby RDF pattern 507. These rows are shown at 514. As specified at 518,the result rows contain three fields, one indicating the conference, oneindicating the number of student reviewers, and one indicating theaverage age of the student reviewers. There are two rows, one for eachconference. The number of student reviewers is computed using the COUNTfunction, which counts the number of rows for each conference in therows returned by the RDF pattern and their average age is computed bythe AVG function. The GROUP BY clause specifies that the results inresult rows 523 are grouped by conference and the ORDER clause specifiesthat the results are ordered by the average age of the studentreviewers.

A PREFERRED EMBODIMENT OF RDF_MATCH: FIGS. 6-8

The following discussion of a presently-preferred embodiment ofRDF_MATCH will begin with a an overview of how table functions areimplemented, will disclose details of RDF triples tables 445 in apreferred embodiment, will then provide a detailed disclosure ofRDF_MATCH's operation, and will finally discuss optimizations. Thepreferred embodiment is implemented using a relational databasemanagement system manufactured by Oracle Corporation, Redwood City,Calif. A table function like RDF_MATCH can, however be implemented inany RDBMS that supports table functions. The optimizations may beimplemented in any RDBMS that supports materialized join views andindexes. Details of the implementation of table functions used in thepreferred embodiment may be found in Data Cartridge Developer's GuideRelease 2 (9.2), Part No. A96595-01, Oracle Corporation, March 2002,which is hereby incorporated by reference into the present patentapplication.

Implementation of Table Functions

Oracle relational database management systems provide users of thesystem with a standard interface for defining and implementing a tablefunction. The interface includes three methods:

-   -   OCDITableStart, which does whatever initialization is required        before the table function can return data;    -   OCDITableFetch, which performs whatever action is necessary to        fetch the data returned by the table function; and    -   OCDITableClose, which does whatever cleanup is necessary after        the table function has ceased returning data.

A user who is defining a table function must provide an implementationfor each of these methods. RDF_MATCH is a built-in table function andimplementations of the methods are provided by Oracle Corporation.

RDF Triples Tables 445: FIG. 6

FIG. 6 shows the RDF triples tables 445 in which the data for an RDFmodel 202 is stored after normalization. There are two main tables:IdTriples 601, which is a list of models and their RDF triples, asrepresented by internal identifiers for the URIs and literals making upthe triple, and UriMap 613, which maps URIs and literals to the internalidentifiers and thus permits conversions between the URIs and literalsand the internal identifiers. This arrangement saves storage space andincreases efficiency by permitting the URIs, which are often lengthy,and the literals, which are also often lengthy and may further have avariety of types, to be replaced in IdTriples table 601 by internalidentifiers having a single type and size.

Continuing in detail with IdTriples table 601, this table has a row 611for every RDF triple in the RDF models that have been loaded into RDBMS401 on which the RDF_MATCH function is being executed. The table hasfour columns:

-   -   ModelID 603, which contains the internal identifier of the model        to which the RDF triple belongs;    -   SubjectID 605, which contains the internal identifier for the        RDF triple's subject;    -   PropertyID 607, which contains the internal identifier for the        RDF triple's predicate; and    -   ObjectID 609, which contains the internal identifier of the RDF        triple's object.

As shown in FIG. 6, IdTriples table 601 shows the rows for the firstfour data triples of data triples 203. It would of course contain a rowfor every schema triple in table 201 and every data triple in table 203.

UriMap table 613 has a single row 619 for every internal identifierwhich appears in IdTriples table 601. There are four columns that are ofinterest in the present context:

-   -   InternalID 615, which contains the internal ID; and    -   RDFVal 617, which specifies a URI or literal value corresponding        to the internal ID;    -   a flag which indicates whether the value of RDFval 617 is the        canonical form for the value;    -   the type of RDFVal 617.

Types include URIs, strings, and integers.

The canonical form for a value is a standard form for writing the value.For example, the numeric value 24 may be written as 024, 24.00, 2.4×10¹,and so on. Depending on the application, any of these may be a canonicalform. In a preferred embodiment, the form the value has when the firstentry is made for the value in UriMap 613 is treated as the canonicalvalue. There is further an index, idx_num 627, that indexes a givennumerical value to a row in UriMap 613 that contains the canonicalrepresentation

RDF Rules Tables 449: FIGS. 17 and 18

The RDF rules that apply to an RDF model 101 are stored in RDF rulestables 449. There are two such tables: rulebase table 1701, whichrelates rules to the rule bases they belong to, and rule table 1709,which includes an entry for each RDF rule that has been input to system401 . Beginning with rule table 1709, the table has a row 1719 for eachrule. Each row contains the rule's name in column 1711, the rule'sleft-hand RDF pattern in column 1713, a filter, which may be null, incolumn 1715, and the rule's right-hand RDF pattern in column 1717. Therule's name must be unique in table 1709. Rulebase table 1701 has a row1707 for each rule that belongs to each rulebase that has been input tosystem 401. Column 1703 contains the name of a rulebase and column 1705contains the name of a rule that belongs to that rulebase. The name ofthe rule in field 1703 is the rule's name from field 1711. As isapparent from this arrangement, a given rule may be part of manydifferent rulebases.

Like models, rulebases may be received as XML files; in such asituation, entries for the rules are added to rule table 1709 andentries for the rules and rulebases to rulebase table 1701. There isfurther an application programmer's interface (API) for creatingrulebases, deleting rulebases, and incorporating rulebases in otherrulebases. FIG. 18 provides an overview of this rulebase API 1801. At1803 and 1805 are shown the functions for creating and droppingrulebases; they take the name of the rulebase being created or droppedas parameters. The functions at 1807 and 1809 permit rules to beinserted into and deleted from a rulebase; the parameters are the nameof the rulebase and the name of the rule.

The interface for creating a rule is shown at 1811; the result of itsexecution is a new entry in rule table 1709. The interface for droppinga rule from a rulebase is shown at 1813; the result of its execution isthe removal of the entry for the specified rulebase and rule fromrulebase table 1701.

Details of the Operation of RDF MATCH: FIG. 8

There are two stages in the operation of RDF_MATCH table function 435.The first stage occurs when RDBMS system 401 compiles the SELECTstatement containing table function 435; the second stage occurs whenthe SELECT statement is executed.

Compile-Time Determination of the Form of the Rows to be Returned byRDF_MATCH:

When the SELECT statement is compiled, it can be determined whichcolumns of the result rows returned by REF_MATCH will be actuallyrequired for the result rows returned by the SELECT statement. Theresults of this determination are provided to RDF_MATCH, which can useit to optimize the queries it makes on RDF triples tables 445.

Execution Time Generation of the Query Performed by the RDF_MATCH TableFunction: FIG. 8

At execution time, the RDF_MATCH table function uses the information inthe RDF pattern contained in the table function to generate a query onRDF triple tables 445 that obtains result rows that have the formspecified in the containing SELECT statement and the values specified bythe variables in the RDF pattern. The query generated by RDF_MATCH willbe termed in the following the generated query. In overview, thegenerated query includes the following:

-   -   a subquery on UriMap 613 to convert the values of literals and        URIs specified in the RDF pattern to their corresponding        internal IDs.    -   a subquery on IdTriples table 601 that uses the internal IDs to        find the triples that satisfy pattern 507.    -   another subquery on UriMap 613 converts the internal IDs in the        results of the subquery on IdTriples table 601 to their        corresponding URI and literal values.

The corresponding URI and literal values are then output as specified at504 in the SELECT statement. The subquery on IdTriples table 601involves self joins. A join is a query that combines rows from two ormore tables. In a self join, the rows that are combined are from thesame table.

FIG. 8 is a flowchart 801 which provides more detail of how RDF_MATCHgenerates and executes the query on RDF triple tables 445. In thepreferred embodiment, the query is generated by the ODCITableStartmethod and executed by the OCDITableFetch method. At 803 is shown thecall to the method, with the method's parameters of an RDF pattern, oneor more RDF models, at least the RDFS rules, and in some cases, aliases.Query generation is shown at 805. The first step is to expand aliasedURIs in the RDF patterns, so that all URIs in the RDF patterns havetheir full URI values (807). The next step is to generate queries onliteral tables 623 and UriMap table 613 to convert the URIs and literalsin the RDF pattern into their corresponding internal identifiers (809).

The next step is to generate a query on IdTriples 601 that produces aresult table containing the rows of IdTriples 601 that satisfy each ofthe triples in the RDF pattern (810). For RDF pattern 507, the resulttable contains all of the rows having the ReviewerOf predicate, all ofthe rows having the predicate rdf:type and an object belonging to theclass Student, and all of the rows having the predicate Age. Thegenerated query that does this is shown at 823. Once the query for theresult table has been generated, a self-join query can be generated onthe result table which returns the set of rows from the result table forwhich the RDF pattern's variables match across the rows as specified inthe RDF pattern (811). In the case of RDF pattern 507, the variable inquestion is the variable ?r, which represents the subject in each of thetriples of pattern 507. The query that is generated for pattern 507 isshown at 827. At step 813, a limitation is added to the generated querythat limits the rows to those belonging to the model specified in theinvocation of RDF_MATCH. In the present case, that is the modelspecified in the invocation with ‘reviewers’.

After the query on IdTriples 601 has been generated, queries aregenerated on UriMap table 613 and literal tables 623 to convert theinternal identifiers in the self-join query results to theircorresponding URI and literal values (815). Finally, the RDF rules thatare specified in the invocation of RDF_MATCH are taken into account byreplacing references to IdTriples table 601 in the generated query withsubqueries or table functions that yield not only the triples explicitlyspecified in the RDF pattern, but also the triples which may be inferredby applying the rules to the explicitly specified triples (817). Ruleprocessing is explained in more detail in the following. Once the queryhas been generated as just described, relational database managementsystem 401 applies its optimizers to the query (818) and then executesthe optimized query (819). The results are output in rows that have thecolumns that were determined at compile time.

Creating RDF Triple Tables 445 and RDF Rule Tables 449

As already described, RDF data sets are generally represented as text intext files and in many cases, the text files are written in a dialect ofXML that has been developed for representing RDF data sets. The RDF dataset contained in a text file may be added to RDF triples tables 445 andRDF rules tables 449 by any technique which reads the text file andconverts its contents into records in RDF triples tables 445 and RDFrules table 449. In general, conversion works as follows:

-   -   extract an RDF triple from the text representation of an RDF        model.    -   for each URI and literal in the triple, determine whether there        is already a row in UriMap 613 for either the URI or the        literal. If there is no row, a new row is made and the Internal        ID field for that row is the internal ID for the URI or literal.    -   When the internal ID for each component of the triple has been        obtained from UriMap, make an entry for the triple in IdTriples        table 601.

With rules, when a rule is encountered in a text file, the text stringsspecifying the rule are written to rule table 1709.

A preferred embodiment of the invention provides a function calledRDF_GENMODEL which can be used in the invocation of RDF_MATCH to specifythe RDF model. RDF_GENMODEL's signature looks like this: RDF_GENMODEL(Webpages RDFWebpages) RETURNS VARCHAR;

The parameter is the URI for a Web page that contains the XMLrepresentation of an RDF model. An invocation of RDF_MATCH that usesRDF_GENMODEL looks like this: SELECT t.a age FROM TABLE(RDF_MATCH(   ‘(?r age ?a)’   RDFModels(RDF_GENMODEL(<web_page_uri>)),   NULL,  NULL)) t WHERE t.a < 25

When RDF_MATCH is invoked at query execution time, RDF_GENMODEL isexecuted. The function reads the XML representation of the RDF modelcontained in the web page and makes non-persistent versions of RDFtriples tables 445 whose entries correspond to the triples in the Webpage. RDF_MATCH then applies the invocation's RDF pattern to the tablesmade by RDF_GENMODEL.

Rule Processing

To handle rules, the RDF_MATCH function replaces references to IdTriplestable 601 in the generated query with subqueries or table functions thatyield not only the triples explicitly specified in the RDF pattern, butalso the triples which may be inferred by applying the rules to theexplicitly specified triples. Rule table 1709 is queried to determinewhat subqueries and/or table functions are necessary to obtain theinferred triples from IdTriples table 601 and the subqueries and/ortable functions are applied to IdTriples table 601. Taking RDF pattern312 and rule 301 as an example, there is a row in rule table 1709 forrule 301. When the RDF query specified in pattern 312 is executed on amodel which includes the rulebase rb, rule table 1709 is queried forrules whose right hand side triple specifies a person who is aReviewerOf a conference; if any are found, the left hand side of thetriple is used as well as the first triple of pattern 301 to selectpeople to whom the remaining triples of pattern 301 are to be applied.

Subqueries are used whenever the required inferencing can be doneconveniently within a SQL query (i.e., without explicitly materializingintermediate results). The inferencing for rule 312 is done in thatfashion. These subqueries generally take the form of a SQL UNION withone UNION component for each rule that yields a triple that selectsentities inferred by the rule, plus one component to select the triplesexplicitly specified in the query. Table functions are used when thesubquery approach is not feasible.

Processing RDFS Inference Rules

The RDFS inference rules require computation of transitive closures forthe two transitive RDFS properties: rdfs:subClassOf (rule rdfs11) andrdfs:subPropertyOf (rule rdfs5). In Oracle RDBMS, these transitiveclosures can be computed using hierarchical queries with the START WITHand CONNECT BY NOCYCLE clauses. Note that CONNECT BY NOCYCLE queries canhandle graphs that contain cycles. The remaining RDFS rules can beimplemented with simple SQL queries.

To ensure that RDFS inferencing can be done within a single SQL query,the user is prohibited from extending the built-in RDFS vocabulary. Thismeans, for example, that there cannot be a property that is asub-property of the rdfs:subPropertyOf property, nor can there be auser-defined rule that yields rdfs:domain triples.

Processing User-Defined Rules

User-defined rules can be classified as follows based upon the extent ofrecursion, if any, in the rule:

-   -   Non-recursive rules: The antecedents cannot be inferred by the        given rule, or any rule that depends on the given rule's        consequents.    -   Simple recursive rules: These rules are used to associate        transitivity and symmetry characteristics with user-defined        properties.    -   Rules that use arbitrary recursion unlike the other two        categories.

Non-recursive user-defined rules can be evaluated using SQL (join)queries by formulating the FROM and WHERE clauses based upon theantecedents and the SELECT clause based on the consequents of the ruleso as to return the inferred triples. Note that the triples that matchthe antecedents of a user-defined rule could themselves be inferred, sothe FROM clause may reference subqueries to find inferred triples.

Simple recursive rules involving transitivity and symmetry can beevaluated as follows. Symmetry can be easily handled with a simple SQLquery. However, handling transitivity with a single SQL query requiressome type of hierarchical query (e.g., using the START WITH and CONNECTBY NOCYCLE clauses in Oracle RDBMS), as in the case of transitive RDFSrules.

The third class of rules involving arbitrary recursion is the mostcomplicated, and it has not been addressed in the presently-preferredembodiment. Because an unknown number of passes over the intermediateresults is required to find all inferred triples, these rules must beevaluated using table functions.

Optimizations of RDF_MATCH: FIGS. 10-16, 19-20

A number of optimizations of RDF_MATCH are possible. The optimizationsfall into two categories:

-   -   adding objects to RDF tables that increase the speed of        execution of the queries specified in the RDF patterns and    -   preprocessing RDF_MATCH to produce a set of declarative SQL        strings that specify a query or queries that are equivalent to        the query generated by RDF_MATCH and rewriting the containing        query by replacing the TABLE construct and RDF_MATCH invocation        with the SQL strings.

Optimization by preprocessing a table function and rewriting thecontaining query using the generated query can be applied to any tablefunction for which a set of declarative SQL strings can be generated atcompile time for the containing query that is completely equivalent tothe query generated by the table function at runtime. The above is thecase when nothing occurs during execution of the table function thatwill affect the form of the result rows returned by the table function.

RDF Optimization Tables 447: FIG. 10

Among the ways in which RDF_MATCH can be optimized by adding tables toRDF optimization tables 447 are the following, shown at 1001:

-   -   Generating materialized join views to reduce the join cost        (1001);    -   Generating subject-property matrix materialized views (1003);    -   Generating indexes for the IdTriples table (1005); and    -   Adding models with inferred triples to the IdTriples table        (1009).        Materialized Views

A SQL query operates on one or more named tables to produce result rows.If the result rows are given names in the SQL query, then the query canoperate on them in the same fashion as it can on any other table. Theultimate source of all the data in an SQL query is one or more basetables which are always present in DBS persistent storage 423. In thepresent context, the base tables are IdTriples 601 and UriMap 613. Thenamed tables made from result rows are termed views of the base tables.For example, the query fragment 823 produces three views of the basetable IdTriples:t1, which contains the rows of IdTriples whosePropertyID indicates the predicate Reviewers, t2, which contains therows whose PropertyID indicates the predicate rdf:type and the ObjectIDStudent, and t3, which contains the rows whose PropertyID indicates thepredicate Age. The relational database management system creates theviews when the query is executed and removes them when they are nolonger needed for the execution of the query. Creating the views takes aconsiderable amount of processing time, and consequently, the speed withwhich a query can be executed can be increased by the use ofmaterialized views. A materialized view is simply a persistent view,that is, one that exists prior to the execution of the query and remainsin existence after its execution. The costs of a materialized view areof course the extra persistent storage that it requires and the costsassociated with keeping the data in the materialized view consistentwith the data in the base tables it is a view of.

Note that the creation of materialized views does not complicate thelogic of RDF_MATCH implementation. That is, the basic scheme ofgenerating a self-join query as described above is still applicable. Theonly difference is that the RDBMS cost-based optimizer optimizes thegenerated self-join query by rewriting it to use materialized viewswhere they are available and their use reduces the cost of the query interms of I/O and CPU time.

Generic Materialized Join Views: FIG. 9 and FIG. 19

If the same variable is used in more than one triple of the searchpattern, the query generated by RDF_MATCH table function 435 involves aself-join of the IdTriples table, as may be seen from the FROM clauseIdTriples t1, IdTriples t2, IdTriples t3 at 823. Depending on how manytriples patterns are specified in the RDF pattern, a multi-way joinneeds to be executed. Since the join cost is a major portion of thetotal processing time, materialized join views can be defined to speedup RDF_MATCH processing. The row size of IdTriples table 601 is smalland hence the trade off between the additional storage space requiredfor materialized views and the extra processing speed they providefavors the use of materialized views. In general, six two-way joins maybe defined on IdTriples table 601, namely joins betweenSubjectID-SubjectID, SubjectID-PropertyID, SubjectID-ObjectID,PropertyID-PropertyID, PropertyID-ObjectID, and ObjectID-ObjectID.Examples of some of these joins are shown at 901 in FIG. 9. In eachcase, a concrete example 903-913 of the join is given along with thenumber of rows in data triples table 203 which will be rows of theself-join:

Which of these six self joins is worth being treated as a materializedview depends on the kinds of RDF patterns that can be expected to occurin the RDF_MATCH function. Selection of the joins to be made intomaterialized views can thus be based on the workload characteristics.The most common joins are typically SubjectID-SubjectID,SubjectID-objectID, and ObjectID-ObjectID. Database management system401 incrementally maintains the materialized join views to keep themcurrent with IdTriples table 601 whenever they are used in a query.

The API for Generic Materialized Views: FIG. 19

FIG. 19 shows the API 1901 used to create and maintain genericmaterialized views. The first function in the API, RDFMViewCardinalities1903, takes the name of an RDF model and optionally the name of an RDFrulebase as parameters. For the RDF model, the function analyzes therows of RDF triples belonging to the RDF model in IdTriples 601 s andthe additional triples inferred by the rulebase specified in therulebase parameter and generates cardinalities of materialized joinviews between Subject-Subject, Subject-Object, Subject-Property,Property-Property, Property-Object, and Object-Object so that a user canestimate the size of the join views to decide whether or not he/shewants to create the join views.

RDFMviewCreate function 1905 creates a generic materialized view basedon the RDF models and optional rule bases specified in the second andthird parameters. The materialized view will contain the model's triplesand the triples inferred from the model using the rule bases. The firstparameter is the name of the materialized view to be created. The fourthparameter specifies the join columns for the materialized view: SSindicates that the subject columns for the triples are the join columns;SO specifies the subject and object columns; SP the subject andpredicate columns; PP the predicate columns, PO the predicate and objectcolumns; and OO the object columns. RDFMViewDrop function 1907 deletes anamed materialized view.

Subject-Predicate Matrix Materialized Views: FIGS. 11 and 19

RDF triples are extremely expressive in the sense that just about anyfact can be expressed using an RDF triple. A table of RDF triples is,however, not ideal for efficient query processing. For example, datatriples table 203 contains a separate row for each of a subject'spredicate-object combinations. John, for instance, has rows for his age,for his membership in the class of Ph.D students, and his function as areviewer for ICDE 2005. Because this is the case, obtaining all of theinformation about John from the table requires a three-way self join.Indeed, if John has n predicate-object combinations, retrieving all ofthe information about John from the table requires an n-way self join.

Query performance can be improved significantly by creating asubject-predicate matrix, that is, a materialized join view in which arow for a particular subject contains a number of different objects towhich the particular subject is related. The objects may be eitherdirectly or indirectly related to the particular subject. Directlyrelated objects are objects that belong to RDF triples that have theparticular subject. Indirectly related objects are objects that belongto RDF triples whose subjects are objects in RDF triples which have theparticular subject. There may of course be more than one level of suchindirection. The columns of the subject-property matrix include a columnfor the subject and a column for each of the kinds of object related tothe subject in the row. FIG. 11 shows at 1101 how a subject-predicatematrix 1105 may be made from a table of RDF triples 1103. The subjectsof subject-predicate matrix 1105 are limited to Ph.D students. For suchsubjects, table 1105 has columns for the subject and columns for kindsof objects that are related to the students in table 1103, namely Ageobjects and StudiesAt objects. There is a row in subject-predicate table1105 for each of the subjects in RDF triples table 1103 that belong tothe class Ph.D student. In table 105, the Age objects are directlyrelated to the subjects John and Pam and the StudiesAt objects areindirectly related to those subjects via the Univ1 and Univ2 objects andsubjects in table 1103.

The subject-predicate matrix can be used to process RDF queriesefficiently. For example, consider RDF pattern 1107, which retrieves theAge and EnrolledAt objects for each student belonging to the class Ph.D. Student and the City objects for the universities that are theEnrolled At objects. Absent materialized view 1105, this query willrequire a 4-way self-join on the IdTriples table (leaving out theconversion between Ids and URIs, for simplicity). However, by using thematerialized view 1105, the query can be processed by simply selectingall the rows from the materialized view. Thus, self-joins can becompletely eliminated in this case. This can lead to significantspeed-up in query processing.

While subject-predicate matrix materialized views are particularlyuseful with tables of RDF triples, they may be used in any situation inwhich self joins are required to collect information about a number ofattributes of a set of entities in a table. A query requiring an n-wayself join to obtain the information about the attributes couldpotentially be processed using a matrix with columns for m-attributesusing (n−m) joins. Such matrices are most efficient in their use ofstorage if each subject in the matrix has one or more objects for eachof the chosen predicates. Some sparseness may be permitted to allowexpanding the group of subjects to include subjects that may have noobjects for a few of the predicates that have columns in the matrix. Itmay be noted that as with materialized views generally, the performancegains from the use of such matrices must be traded off against the extraspace required.

The API for making a subject-property materialized view is shown at 1909in FIG. 19. The function takes five parameters: a name for the newmaterialized view, the RDF model or models to which it is to apply, therulebase or rulebases from which RDF triples may be inferred from themodel, an RDF pattern 205 whose predicates are to be columns in thematerialized view, and a filter for the table's rows.

Indexing IdTriples Table 601: FIGS. 12 and 13

A common way of speeding up access to information in an RDBMS table isto provide an index for the table. Indexes on tables work exactly thesame way as indexes in books. An index entry in a book has a word orphrase followed by a list of the numbers of the pages in the book onwhich the word or phrase occurs. The index in the book speeds access bypermitting the reader to go directly to the page or pages of interest.Conceptually, an index entry for an RDBMS table consists of a value froma row of the table followed by a row number for the row that containsthe value. The value may be made by concatenating several fields of therow. The index on the table speeds access to the table by permitting theRDBMS to go directly to the indexed row or rows. RDBMS systems typicallyprovide built-in facilities for creating a number of different kinds ofindexes. The kind of indexes used in the preferred embodiment are the Btree indexes provided by the Oracle database system in which thepreferred embodiment is implemented.

As was the case with materialized views, the RDBMS's optimizerautomatically determines whether there are indexes to a table beingqueried and if so, whether using one of the index will reduce theprocessing time required for the query in question. An important metricused by the optimizer is selectivity. Selectivity refers to thepercentage of rows in a table that are returned by a query. A query isconsidered highly selective if it returns a very limited number of rows.A query is considered to have low selectivity if it returns a highpercentage of rows. The more selective a query is, the greater the costsavings from using an index.

FIG. 12 shows at 1201 data triples table 203 in which each row has beenassigned a row number 1203. Index 1205 is an index for data triplestable 203 which indexes the table according to values from each row thatare made by concatenating table 203's Predicate, Subject, and Objectfields in the row. Conceptually, index 1205 may be seen as a table witha Predicate column 1207, a Subject column 1209, an Object column 1211,and a Rownum column 1213. Each row 1215 of index 1205 is an index entry.The entry 1215 contains the values of the Predicate, Subject, and Objectfields of a single row of data triples table 203 and the value of RowNumin entry 1215 is the row number of the single row in table 203. Ofcourse, in some cases, there may be more than one row of the indexedtable that corresponds to an index entry 1215, and in that case, therewill be a list of row numbers at 1213. In index 1205, the index entryincludes values from the Predicate, Subject, and Object fields in thatorder, and in the terminology used in the following, index 1205 is a(predicate, subject, object) index.

As mentioned earlier, most of the work involved in executing the querygenerated by RDF_MATCH is performing self joins on IdTriples table 601.Since the self joins involve repeatedly referencing the rows ofIdTriples table 601, having indexes that are adapted to the kinds ofqueries generated by RDF_MATCH is critical for the performance ofRDF_MATCH. In the following, the self-join queries generated byRDF_MATCH are analyzed to determine which columns of IdTriples table 601should be indexed for optimal query performance. The analysis isperformed using the information 1301 in FIG. 13. There are typically twotypes of RDF patterns:

-   -   1. those in which, for a given predicate, subject is joined with        subject, or object with object, as shown in RDF pattern 1303,        which joins rows whose subjects belong to the domain of the        ReviewerOf predicate with rows whose subjects belong to the        domain of the Age predicate.    -   2. those in which for a given predicate, subject is joined with        object, as shown at 1305, in which joins rows whose objects        belong to the range of the ReviewerOf predicate with rows whose        subjects belong to the domain of the rdf:type predicate.

The same query patterns can be observed as more triples are added.

Since IdTriples 601 only has three columns, only the following fivekinds of indexes for predicates can be built on the table:

-   -   1. (PropertyID),    -   2. (PropertyID, SubjectID),    -   3. (PropertyID, SubjectID, ObjectID).    -   4. (PropertyID, ObjectID)    -   5. (PropertyID, ObjectID, SubjectID)

Index (1) above will be termed in the following a single-column index;indexes (2) and (4) will be termed two-column indexes; indexes (3) and(5) will be termed three-column indexes. With queries that returns lessthan 20% of the records in IdTriples 601, and are therefore highlyselective, indexes such as (3) and (5) above, which use the values ofall three columns in a row's index entry, have been found to be mostefficient.

Optimizing Inferencing: FIGS. 7 and 10

Rulebases specified in the RDF_MATCH table function's parameters areapplied, by default, during query processing to the specified list ofRDF models. However, if a rulebase is used frequently, then a new modelcontaining the RDF triples inferred from one or more rule bases can beadded to IdTriples table 601. The new model can then be used to speed upquery execution. This is shown at 1009 in FIG. 10, where model A 1011 inIdTriples table 601 has triples 1013. To optimize execution of RDFqueries on model A, a new model A_inferred 1015 has been added toIdTriples table 601. The new model 1015 includes the triples 1017 thathave been inferred by the application of one or more rulebases totriples 1013 of model A. To take advantage of A_inferred model 1015, theModels parameter for the invocation of the RDF_MATCH table functionincludes both model A 1011 and model A_inferred 1015 but the RuleBasesparameter does not include the rulebase or rulebases that were used toproduce A_inferred 1015. When this is done, RDF_MATCH simply uses thetriples in the models A and A_inferred rather than using the rulebasesto infer the inferred triples from model A.

In other embodiments, inclusion of a set of inferred triples may betransparent to the user. In such an embodiment, the inferred triples canbe stored in a separate table in which they are related to the model thetriples are inferred from and the rulebase used to infer them. When aninvocation of RDF_MATCH specifies a rulebase, the code for the functionchecks whether there are inferred triples for the model and rulebasespecified in the invocation, and if there are, the code does not againinfer the triples, but instead joins the inferred triples from the rowsfor the model and rulebase in the inferred triples table to the triplesfrom the model.

FIG. 7 shows the API used to add models with inferred rules to IdTriplestable 601. The API used to add a model with inferred rules is shown at711; it takes as parameters the model to which the rulebase is to beapplied, the rulebase, and a name for the new model that will containthe triples inferred by applying the rules specified by the rule base tothe specified model. The result of executing CreateRulesIndex is that amodel 1015 will be added to IdTriples table 601 that has the nameindicated in the last parameter and the additional triples that areinferred by applying the rule base of the second parameter to the modelspecified in the first parameter. The API used to drop a modelcontaining inferred rules is shown at 713; the only parameter is thename of the index to be dropped.

Eliminating the Overhead of the Table Function: FIGS. 14-16

The SQL table function mechanism is a general purpose mechanism forconverting data that is accessible to the table function into rows. Themechanism works not only with table functions that obtain their datafrom existing relational tables, as is the case with RDF_MATCH, but alsowith table functions that read their data from files, fetch the dataacross the World Wide Web, or even receive feeds of data such as stockprice information. One consequence of the generality of the tablefunction mechanism is substantial overhead. For example, the timet_(total) required for processing an RDF pattern using RDF_MATCH tablefunction 435 has the following components:t _(total) =t _(core) +t _(sql2proc) +t _(proc2canonical) +t_(canonical2sql)

Here t_(core) represents the core processing time, that is, the cost ofexecuting the SQL query that is generated by RDF_MATCH and performs theself-joins on IdTriples table 601 and any additional joins on UriMaptable 613. Once the result rows of the generated query have beencomputed, the table function mechanism copies the rows into variables ofRDF_MATCH (t_(sql2proc)) and then converts the values of these variablesto a canonical format (t_(proc2canonical)) for the table functionmechanism so that the mechanism can return the values to the containingquery. When the mechanism returns the values in the canonical format tothe containing query, it transforms them back into rows(t_(canonical2sql)).

The processing time represented by t_(total)−t_(core) depends on thesize of the result set returned by the table function to the tablefunction mechanism and hence t_(total)−t_(core) will dominate the costof executing the table function when the table function result set sizeis large. This is shown in graph 1401 in FIG. 14. Graph 1401 shows howt_(total) in seconds for RDF_MATCH increases with the number of resultrows returned by the query generated by RDF_MATCH. Graph 401 1401further shows how t_(core) 1403, t_(sql2proc) 1405, t_(proc2canonical)and t_(canonical2sql) 1407, and other 1409 make up t_(total).

As is apparent from graph 1401, eliminating the conversion overhead oft_(sql2proc), t_(proc2canonical) and t_(canonical2sql) would enormouslyreduce the amount of time required to execute RDF_MATCH where RDF_MATCHreturns a significant number of rows. That it should be possible toeliminate the conversion overhead can be seen from the fact that withRDF_MATCH, the conversions are performed on result rows from relationaldatabase tables, that is, on data that is already in the form requiredfor the containing query. What the conversions do is convert result rowsreturned by the generated query to values of variables in RDF_MATCH,convert the variable values to the table function mechanism's canonicalform, and then convert the values in the canonical form back into resultrows that have the same form as the ones returned by the generatedquery.

In the case of table functions like RDF_MATCH, in which the tablefunction obtains its data by means of a query on a set of relationaltables, the conversion overhead can be eliminated by rewriting the querycontaining the table function such that the query used by the tablefunction to obtain the data replaces the table function in thecontaining query. This is shown in FIG. 15. At 1501 is shown a querythat employs the table function RDF_MATCH (1503). The RDF pattern usedin the table function is shown at 1505. At 1507 is shown the query whichRDF_MATCH generates from RDF pattern 1505; at 1509 is shown rewrittenquery 1501 in which table function 1503 has been replaced by generatedquery 1507.

The query rewrite of FIG. 15 can of course always be done by hand;however, the table function mechanism can be modified to rewrite thequery containing the table function, and consequently, a version of thetable function mechanism can be created which does the following:

-   -   given a table function, use the table function to generate a        query;    -   return the query generated by the table function;    -   rewrite the containing query so that the generated query        replaces the TABLE construct and the table function invocation        in the containing query;    -   reparse the rewritten containing query; and    -   execute the rewritten containing query.

In the following, this new version of the table function mechanism willbe termed the table function rewrite version. The table function rewriteversion may be used in any situation where the rows returned by thetable function may be declaratively defined, as is the case where theycan be defined by an SQL query.

In a preferred embodiment, the table function rewrite version of thetable function mechanism is implemented by adding an ODCITableRewritemethod to the definition of the table function. The method defines howthe table functions parameters are to be used to generate an SQL querythat can replace the TABLE construct and the table function in thecontaining SELECT statement. When the containing query is being compiledby the SQL compiler, the compiler executes the ODCITableRewrite methodto obtain an SQL query that is equivalent to the table function. Thecompiler then replaces the TABLE construct and the RDF_MATCH invocationwith the SQL query. At 1415 is shown an example of a query withRDF_MATCH invocation 1503. The rewritten query which results is shown at1419. In query 1419, the TABLE construct and the invocation of RDF_MATCHhave been replaced by query 1507 generated by the ODCITableRewritemethod.

In addition to using the ODCITableRewrite method to generate the queryrequired to rewrite the containing query, the table function rewriteversion of the table function mechanism must perform additional typechecking to ensure that the columns referenced in the containing queryare indeed returned from the generated SQL query as well as to ensurethat the data types for columns referenced in the outer query arecompatible with the source datatypes in the generated SQL query. Theadditional type checking overhead required is, however, small, andunlike the conversion overhead of the present table function mechanism,does not increase with the size of the result set returned by the tablefunction. The exact mechanism used to obtain the SQL string is of courseimmaterial; it may be, as above, a method associated with the tablefunction or it may be a function that takes the table function as aparameter.

FIG. 16 is a flowchart 1601 of how the table function rewrite version ofthe table function mechanism operates in a preferred embodiment. Theprocessing is done during the compilation phase 1603 of SQL queryprocessing. At 1604, compilation continues until the compilation isfinished (1606). If a table function is encountered (1605), the compilerfirst determines whether the table function has a rewrite method (1611).If it does not, the table function is processed in the usual manner(1608) and compilation continues (1606) If the table function does havea rewrite method, the rewrite method is executed (1615). If the resultof the execution is not an SQL string, the table function is processedin the usual manner and compilation continues (1608, 1606). If theresult is an SQL string, the compiler replaces the table functioninvocation and the TABLE construct with the returned SQL string (1617).The compilation phase then reparses the rewritten query (1619).Compilation of the containing query then continues until it is finished.

Then the optimization stage of query generation is entered andoptimization is done on the containing query as rewritten. As importantadvantage of rewriting the containing query with SQL that is equivalentto the table function is that the equivalent SQL is available to theoptimizer. With standard table functions, the optimizer can optimize thequeries generated by the table function and can optimize the containingquery, but when the optimizer is optimizing the containing query, itmust treat the table function as a “black box” and cannot take thequeries generated by the table function into account. Once optimizationis done, the containing query is executed with the replacement string.Here, because the table function has been eliminated, there is no needto perform the conversions that accompany the invocation of and returnfrom the execution of the table function. At 1602 is shown a flowchartof the rewrite method. At 1625, the rewrite method is invoked by thecompiler using the parameters from the table function. At 1627, therewrite method determines whether the parameter values permit a rewrite.If they do not, the method does not return an SQL string (1629). If theparameter values do permit a rewrite, the rewrite method uses theparameters to write an SQL string that is equivalent to the tablefunction (1631) and then returns the equivalent SQL string to thecompiler. It is thus up to the writer of the rewrite method to determinewhen it is possible to write an SQL string that is equivalent to thetable function.

How the SQL string is written in step 1631 of course depends on theparameters and the tables the query is written over. In the case ofRDF_MATCH, generating the SQL string involves substantially the samesteps as generating the query when RDF_MATCH is executed. These stepsare shown at 805 in FIG. 8. The difference between FIG. 8 and theprocessing shown in FIG. 16, of course, is that in FIG. 8, the SQLstring for the query is generated at runtime and is executed inside theexecution of RDF_MATCH; in FIG. 16, the SQL string for the query isgenerated at compile time and replaces the execution of RDF_MATCH.Because the SQL string replaces the execution of RDF_MATCH, the run timeoverhead resulting from the execution of the table function iseliminated. Included in the eliminated overhead are copying the resultsfor the select list items of the containing SQL query to the respectiveattributes of the table function return object instance, passing theresulting object instance via the table function infrastructure, andremapping the passed object instance to the selected list items.

Other Examples of the Use of ODCITableRewrite: FIG. 20

FIG. 20 contains other examples of the use of ODCITableRewrite. At 2001is shown how ODCITableRewrite may be used to replace an invocation ofthe table function tab_func with an SQL string. The original query withthe invocation of tab_func is shown at 2003; the query that is generatedwhen tab_func is executed is shown at 2005; the original query with theTABLE construct and the invocation of tab_func replaced by query string2005 is shown at 2007.

Table functions may be used with SQL constructs other than the TABLEconstruct. The TABLE construct and other such constructs will be termedin the following table function containers. The effect in the TABLEconstruct and elsewhere is to parameterize the table function container,i.e., what result rows are returned by the table function container isdetermined by the parameters used in the table function. At 2009 in FIG.20 is shown how a parameterized view may be used as a table functioncontainer. The parameterized view is called summaries. It returns asummary for a given period of time from a given table, with the giventable and given period of time being determined by the parameterizedview's parameters. The SQL-DDL for creating the parameterized view isshown at 2011. USING clause 2013 specifies how the result rows specifiedby the view will be obtained; in this case they are obtained byexecuting the table function sum_tab_function 2012; the parameterfact_table specifies a table from which the summary is going to be madeand the parameter time_granularity specifies the period of time. At 2015is shown a SELECT statement that obtains its result rows from theparameterized view summaries 2016. The parameters 2014 in summaries arethe parameters required for sum_tab_function 2012. Here, the table is atable of sales and the time period is a year.

If the table function has a rewrite method, the summaries parameterizedview may be replaced by an SQL string generated by the rewrite method inthe same fashion that the TABLE construct is replaced in the firstexample. The SQL string generated by the rewrite method forsum_tab_function 2012 is shown at 2017; and 2019 is shown the SELECTstatement of 2015 in which parameterized view 2016 has been replaced bystring 2017.

CONCLUSION

The foregoing Detailed Description has disclosed to those skilled in therelevant technologies how the overhead involved in the execution of atable function may be reduced by generating an SQL string that returns aset of result rows equivalent to the set of result rows returned by thetable function and rewriting the SQL query that contains the tablefunction such that the SQL string replaces the container for the tablefunction. Rewriting the SQL query in this fashion also makes it possibleto apply the relational database system's optimizer to the rewritten SQLquery. The Detailed Description has further disclosed the best modepresently known to the inventors of implementing their rewritetechnique.

In the foregoing Detailed Description, the rewrite technique is appliedto a TABLE function that is used to integrate RDF data into a relationaldatabase system, but those skilled in the relevant technologies willimmediately appreciate that the technique can be used with many TABLEfunctions. The preferred embodiment of the technique is of coursedetermined by the fact that the TABLE function with which it is usedperforms queries on RDF data and by the fact that the table functionmechanism of the preferred embodiment is that provided for therelational database system in which the preferred embodiment isimplemented. As is always the case with software-implemented inventions,there is also the latitude which software affords the implementer forhis implementation. For all of the foregoing reasons, the DetailedDescription is to be regarded as being in all respects exemplary and notrestrictive, and the breadth of the invention disclosed herein is to bedetermined not from the Detailed Description, but rather from the claimsas interpreted with the full breadth permitted by the patent laws.

1. A relational database management system of the type wherein a tablefunction returns a set of result rows which are represented in an SQLstatement by a container for the table function, the relational databasemanagement system having the improvement comprising: a rewrite methodassociated with the table function that returns an SQL string that whenexecuted will return an equivalent set of result rows, the relationaldatabase system executing the rewrite method prior to executing thecontainer to obtain the SQL string and thereupon rewriting the SQLstatement such that the container for the table function is replaced bythe returned SQL string.
 2. The relational database management systemset forth in claim 1 wherein: the table function has a parameter; andthe rewrite method uses the parameter in producing the returned SQLstring.
 3. The relational database management system set forth in claim2 wherein: the rewrite method determines from the parameter whether itis possible to produce the SQL string and provides an indication when itis not possible; and the relational database management system respondsto the indication by not rewriting the SQL statement.
 4. The relationaldatabase management system set forth in claim 1 wherein: the rewritemethod determines whether it is possible to produce the SQL string andprovides an indication when it is not possible; and the relationaldatabase system responds to the indication by not rewriting the SQLstatement.
 5. The relational database management system set forth inclaim 4 further comprising: a runtime execution method that isassociated with the table function, the relational database managementsystem executing the runtime execution method when the container isexecuted if the rewrite method has determined that it is not possible toproduce the SQL string.
 6. The relational database management system setforth in claim 1 further comprising: a runtime execution method that isassociated with the table function, the rewrite method being optionaland the relational database management system executing the runtimeexecution method when the container is executed if the rewrite method isnot present.
 7. The relational database management system set forth inclaim 1 wherein: the relational database system further optimizes therewritten SQL statement.
 8. The relational database management systemset forth in claim 1 wherein: the rewrite method is optional; and ifthere is no rewrite method, the relational database system does notrewrite the SQL statement.
 9. The relational database management systemset forth in claim 1 wherein: the table function and the rewrite methodare provided by the relational database management system.
 10. Therelational database management system set forth in claim 1 wherein: thetable function and the rewrite method are provided by a user of therelational database management system.
 11. The relational databasemanagement system set forth in claim 1 wherein: the container is a TABLEclause.
 12. The relational database management system set forth in claim1 wherein: the container is a parameterized view that is defined usingthe table function.
 13. A storage device that is accessible to aprocessor, the storage device being characterized in that: the storagedevice contains code which, when executed by the processor, implementsthe apparatus set forth in claim
 1. 14. A method practiced in arelational database management system of the type wherein a tablefunction returns a set of result rows which are represented in an SQLstatement by a container for the table function, the method comprisingthe steps of: receiving the SQL statement; making an SQL string that,when executed, will return an equivalent set of result rows; andrewriting the SQL statement such that the container is replaced with theSQL string prior to executing the SQL statement.
 15. The method setforth in claim 14 wherein: the table function has a parameter; and theparameter is used in the step of making the SQL string.
 16. The methodset forth in claim 15 wherein the parameter is used in the step ofmaking the SQL string to determine whether it is possible to make theSQL string and the method further comprises the steps of: providing anindication when it is not possible to produce the SQL string; andresponding to the indication by not performing the step of rewriting theSQL statement.
 17. The method set forth in claim 14 wherein the methodfurther comprises the steps of: providing an indication when it is notpossible to produce the SQL string; and responding to the indication bynot performing the step of rewriting the SQL statement.
 18. The methodset forth in claim 17 further comprising the step of: executing thetable function when the SQL statement is executed.
 19. The method setforth in claim 14 wherein the step of making the SQL string is optionaland the method further comprises the step performed when the step ofmaking the SQL string is not performed of: executing the table functionwhen the SQL statement is executed.
 20. The method set forth in claim 14further comprising the step of: optimizing the SQL statement after theSQL statement has been rewritten.
 21. The method set forth in claim 14wherein: the step of making the SQL string is optional; and if the stepof making the SQL string is not performed, the step of rewriting the SQLstatement is also not performed.
 22. The method set forth in claim 14wherein: in the step of receiving the SQL statement, the container is aTABLE clause.
 23. The method set forth in claim 14 wherein: in the stepof receiving the SQL statement, the container is a parameterized viewthat is defined using the table function.
 24. A storage device that isaccessible to a processor, the storage device being characterized inthat: the storage device contains code which, when executed by theprocessor, implements the method set forth in claim 14.